package durose.system.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import durose.system.dict.CommonDict;
import durose.system.dict.ResponseDict;
import durose.system.pojo.Sys_menu;
import durose.system.service.Sys_menuService;

/**
 * 菜单管理控制类
 * @author Administrator
 *
 */
@Controller
public class Sys_menuController {
	String prefix = "system/durose/sys_menu/";
	
	@Autowired 
 	 Sys_menuService sys_menuService;

	

	
	@RequestMapping("sys_menu")
	public String sys_menuGet(){
		return prefix+"sys_menu";
	}
	
	@RequestMapping("sys_menu_list")
	@ResponseBody
	public Object sys_menuList(@RequestParam(value="pageNumber",defaultValue="0")Integer pagenumber,@RequestParam(value="queryName",required=false) String queryName){
		PageHelper.startPage(pagenumber,CommonDict.PAGE_SIZE);
		PageInfo<Sys_menu> page = new PageInfo<>(sys_menuService.sys_menuList(queryName));
		return page;
	}
	
	@RequestMapping("sys_menu_add")
	@ResponseBody
	public Object sys_menuAdd(Sys_menu pojo){
		sys_menuService.sys_menuAdd(pojo);
		return new ResponseDict(CommonDict.BUS_STATUS_OK);
	}
	
	@RequestMapping("sys_menu_add_page")
	public String sys_menuAddPage(Model model){
		model.addAttribute("sys_menus", sys_menuService.sys_menuParentList(0));

		return prefix+"sys_menu_add";
	}
	
	@RequestMapping("sys_menu_edit")
	@ResponseBody
	public Object sys_menuEdit(Sys_menu pojo){
		sys_menuService.sys_menuUpdate(pojo);
		return new ResponseDict(CommonDict.BUS_STATUS_OK);
	}
	
	@RequestMapping("sys_menu_edit_page")
	public String  sys_menuEditPage(int id,Model model){
		model.addAttribute("sys_menus", sys_menuService.sys_menuParentList(0));

		model.addAttribute("sys_menu", sys_menuService.sys_menuGet(id));
		return prefix+"sys_menu_edit";
	}
	
	@RequestMapping("sys_menu_delete")
	@ResponseBody
	public Object sys_menuDelete(int id){
		sys_menuService.sys_menuDelete(id);
		return new ResponseDict(CommonDict.BUS_STATUS_OK);
	}
	
	
}
